﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using devtm.Helpers;
using devtm.Configuration;

namespace devtm.Editor.Configuration
{
    /// <summary>
    /// Interaction logic for TitleTreeview.xaml
    /// </summary>
    public partial class TitleTreeview : UserControl, IDisposable
    {
        public TitleTreeview()
        {
            InitializeComponent();
            
        }


        public IContainerHeader Context
        {
            get
            {
                return (IContainerHeader)base.DataContext;
            }
            set
            {

                if (base.DataContext != null)
                    Context.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(value_PropertyChanged);

                base.DataContext = value;
                
                image1.Source = value.Image;
                image1.Stretch = Stretch.Uniform;
                imageInherit.Visibility = value.Inherited;
                imageError.Visibility = value.SectionInError;
                value.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(value_PropertyChanged);

            }

        }

        void value_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            image1.Source = Context.Image;
            image1.Stretch = Stretch.Uniform;
            imageInherit.Visibility = ((IContainerHeader)base.DataContext).Inherited;
            imageError.Visibility = ((IContainerHeader)base.DataContext).SectionInError;
        }
        
        public void Dispose()
        {
            if (base.DataContext != null)
                Context.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(value_PropertyChanged);
        }

    }
}
